﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;
using WindowsForms.AOnline.View.Dictionary;

namespace WindowsForms.AOnline.Presenter.Dictionary.EmployTest
{
    public class EmployTestPresenter : Presenter<IEmployTestView>  
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountPresenter" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public EmployTestPresenter(IEmployTestView view)
            : base(view)
        {
        }

        /// <summary>
        /// Displays the specified employ identifier.
        /// </summary>
        /// <param name="employId">The employ identifier.</param>
        public void Display(string employId) 
        {
            if (employId == null) { View.EmployId = 0; return; }
            var employ = Model.GetEmploy(int.Parse(employId));
            View.EmployId = employ.EmployId;
            View.EmployName = employ.Name;
            View.Salary = employ.Salary;
            View.DepartmentId = employ.DepartmentId;
        }

        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public string Save()
        {
            var employ = new EmployTestModel    
            {
                EmployId = View.EmployId,
                Name = View.EmployName,
                Salary = View.Salary,
                DepartmentId = View.DepartmentId
            };

            if (View.EmployId == 0)
                return Model.AddEmploy(employ);
            return Model.UpdateEmploy(employ);
        }

        /// <summary>
        /// Deletes the specified employ identifier.
        /// </summary>
        /// <param name="employId">The employ identifier.</param>
        /// <returns>System.Int32.</returns>
        public string Delete(int employId) 
        {
            return Model.DeleteEmploy(employId);
        }
    }
}
